package com.wxd.thread;

public class movieRunable implements Runnable {
    private int ticketNum = 100;
    private Object obj = new Object();

    @Override
    public void run() {
        while (true) {
            synchronized (obj) {
                if (ticketNum > 0) {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName() + "正在出售第" + ticketNum + "张票");
                    ticketNum--;
                }
            }
        }
    }
}
